<?php

class BookDetailsRenderer extends TRepeaterItemRenderer
{
	public function onInit($param)
    {
		$this->populateDetails();
		
		// permission, to hide delete button
		$this->VerifyOwner();
	}
	
	public function VerifyOwner()
	{
		if($this->getPage()->isNavigatedUserSameAsOwner())
		{ // showing owner profile...
		
			
		}			
		else // showing someone else profile
		{
			// hide delete
			$this->btnDeleteBook->Visible = false;
		}
	}
	
	public function populateDetails()
	{
		$this->SetBookName();
		$this->SetBookLoad();
	
	}
	
	public function SetBookLoad()
	{
		$this->linkBook->setAttribute('onclick','initBook('. $this->Data->book_id .')');
	}
	
	public function SetBookName()
	{
		$bookData = BookDataRecord::finder()->find('book_id = ?', $this->Data->book_id);
		
		$this->nameBook->Text = $bookData->book_name;
	}
	
	
	public function btnDeleteBook_click()
	{
		
		// Delete at BookDataRecord
		BookDataRecord::finder()->deleteByPk($this->Data->book_id);
		
		// Delete at BookIDRecord
		BookIDRecord::finder()->deleteAll('book_id = ?', $this->Data->book_id);
		
		$this->Response->reload();
	}
}
?>
